var PATH_PREFIX = "";
function setPathPrefix(path) {
	PATH_PREFIX = path;
}

$(function(){
	var $publicEmailList = $('#publicEmailList');
	$publicEmailList.jqGrid({
		caption: '主消息配置列表<button type="button" class="btn btn-default btn-sm btn-small btn-fullscreen" title="" tabindex="-1"><i class="fa fa-arrows-alt icon-fullscreen"></i></button>',
		url:  PATH_PREFIX+'msgpublicemail/publicEmailListPage.do',
		datatype: "json",
		colNames: ['id', '公共邮箱名称' , '公共邮箱地址', '操作'],  
		colModel: [
				  {name:'id',index:'id',hidden:true, align:'left',key:true},
				  {name:'emailName',index:'emailName',align:'left',sortable:false},
				  {name:'email',index:'email',align:'left',sortable:false},
				  {name:'option',index:'option',  resizable:true, align:'left', sortable:false}
				  ],
		rowNum:20,        
		rowList:[20,30,50],
		rownumbers : true,
		rownumWidth : 50,
		prmNames: {
			search: "search",
			page: "pageNo",     //当前页
			rows: "limit"         //每页行数
		},  
		height: 'auto',
		autowidth : true,
		width: false,
		editurl : '',
		viewrecords : true,
		cellEdit : false,
		shrinkToFit : true,
		grouping : false,
		autowidth : true,
		jsonReader: {  
			root: "items",       //结果集
			records: "total", //总记录数 
			total: "pageCount",	  //总页数
			page: "pageNo",	  //当前页 
			repeatitems : false       // (4)  
		},
		pager: "#publicEmailPage", 
		viewrecords: true,
		hidegrid : false,
		multiselect:false,
		
		gridComplete: function(){
			
			var ids = $publicEmailList.jqGrid('getDataIDs');
			for(var i=0;i < ids.length;i++){
				var id = ids[i];
				var ve = '<a href="javascript:void(0);" class="btn btn-link btn-jqgrid" title="修改" onclick="publicEmailEdit(\''+id+'\');"  ><i class="fa fa-pencil-square-o"></i></a>';
				jQuery("#publicEmailList").jqGrid('setRowData',ids[i],{option:ve});
			}
			
		}
		
	});
	
	$publicEmailList.navGrid('#publicEmailPage', {
		edit : false,
		add : false,
		del : false,
		search : false,
		refreshstate : 'current'
	});
	$publicEmailList.jqGrid('setFrozenColumns');
	jqGridResize($publicEmailList);	
});


function queryByCondtion (flag) {
    if (flag) {
    	$("#publicEmailList").trigger("reloadGrid",[{page:1}]);//重新载入Grid表格
    } else{
    	$("#publicEmailList").trigger("reloadGrid");//重新载入Grid表格
	}
}

// 对按钮绑定全屏事件
$(document).on('click', '.btn-fullscreen', function() {
	var $wrapper = $(this).parents('.fullscreen-wrapper')[0];
	toggleFullScreen(document.documentElement);
	// 全屏的时候将几个模态框放到下面去
	$('.modal[role="dialog"]').appendTo($wrapper);
});


function addPublicEmail(){
	 var actionUrl = PATH_PREFIX+"msgpublicemail/publicEmailAddView.do";
	 openDialog(actionUrl);
}

function publicEmailEdit(id){
	var actionUrl = PATH_PREFIX+"msgpublicemail/publicEmailUpdateView.do?id=" + id;
	openDialog(actionUrl);
}